package TDALista;
import java.util.Iterator;
import java.util.NoSuchElementException;

public class IteradorLista<E> implements Iterator<E> {
	protected PositionList<E> lista;
	protected Position<E> cursor;
	
	public IteradorLista(PositionList<E> p){
		lista=p;
		if (lista.isEmpty()){cursor=null;}
		else{
			try{
			 cursor=lista.first();}
			catch(EmptyListException e){e.getMessage();}
		}
	}

	public boolean hasNext(){
		return (cursor!= null);
	}
	
	public E next() throws NoSuchElementException{
	   if (cursor== null) throw new NoSuchElementException ("No hay elemento siguiente");
			E toReturn=null;
				try{
					toReturn= cursor.element();
					if (cursor== lista.last()){cursor= null;}
						else{cursor= lista.next(cursor);}
			} 
		  catch(InvalidPositionException e3){System.out.println("e.getMessage()");}
		  catch(BoundaryViolationException e2){System.out.println("e.getMessage()");}
		  catch(EmptyListException e1) {System.out.println("e.getMessage()");}

	  return toReturn;
	}
	
	public void remove(){}
}